package com.ruoyi.web.controller.rjgc;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.Category;
import com.ruoyi.littleRedBook.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/category")
@Api(tags = "商品分类管理")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/list")
    @ApiOperation("获取所有启用的商品分类（支持多级）")
    public AjaxResult getEnabledCategoryList() {
        return categoryService.getEnabledCategoryList();
    }

    @GetMapping("/list/parent/{parentId}")
    @ApiOperation("根据父分类ID获取子分类")
    public AjaxResult getChildCategoryList(@ApiParam("父分类ID，0表示顶级分类") Long parentId) {
        return categoryService.getChildCategoryList(parentId);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取分类详情")
    public AjaxResult getCategoryById(@ApiParam("分类ID") Long id) {
        return categoryService.getCategoryById(id);
    }
}
